//
//  BattleActionLayer.h
//  airfight
//
//  Created by aaron more on 12-8-21.
//  Copyright (c) 2012年 moonriver. All rights reserved.
//

#ifndef airfight_BattleActionLayer_h
#define airfight_BattleActionLayer_h

#include "cocos2d.h"
#include <queue>
#include "../resources.h"
#include "../env.h"
#include "extensions/CCNotificationCenter/CCNotificationCenter.h"
#include "PayOffLayer.h"
#include "PlayerFighterSprite.h"
#include "EnemyFighterSprite.h"
#include "EnemyBulletSprite.h"
#include "BulletSprite.h"
#include "BonusSprite.h"
#include "Stage.h"
#include "Background.h"
#include "Box2D.h"
#include "CollisionListener.h"
#include "GLES-Render.h"
#include "FighterMoveByAction.h"
#include "FighterMoveBezierThreeByAction.h"
#include "FighterMoveBezierTwoByAction.h"
#include "DBManager.h"

USING_NS_CC;
USING_NS_CC_EXT;

enum Fighter_Tags
{
    kTagPlayerFighterNode = -1,
    kTagPlayerFighter = 0,
};

class BattleActionLayer : public CCLayer
{
    
private:
    CCSize screenSize;
    CCSprite *frontGround;
    CCSprite *frontGroundRe;
	CCSprite *rearGround;
    CCSprite *rearGroundRe;
    int frontGround_rollingSpeed;
    int rearGround_rollingSpeed;
    
    CCScene *parent;
    
    CCSpriteFrameCache *m_SpriteFrameCache;
    
    
    CCSprite *m_LifeBarBack;
    CCSprite *m_LifeBar;
    CCProgressTimer *m_LifeProgress;
    
    CCMenuItemSprite *m_PauseButton;
    CCMenu *m_PauseButtonMenu;
    b2World *m_World;
    CollisionListener *m_Listener;
    GLESDebugDraw *m_debugDraw;

    Stage *stage;

    //queue<BonusSprite*> toDestroyBonuses;
    
    
    
    int m_iElapseFrame;
    bool m_bPaused;
    int playerFullBlood;
    static BattleActionLayer *m_pInstance;
    
public:
    CCSpriteBatchNode *m_SpriteBatch;
    PlayerFighterSprite* m_PlayerFighterSprite;
    CCDictionary *bonusDict;
    
public :
    BattleActionLayer();
    virtual ~BattleActionLayer();
    
    static BattleActionLayer* getInstance()
    {
        if (!m_pInstance)
        {
            m_pInstance = BattleActionLayer::create();
        }
        
        return m_pInstance;
    }
    
    virtual bool init(/*CCDictionary *p_params*/);
    virtual void onEnter();
    virtual void onExit();
    virtual void draw();
    void update(float dt);
    
    void initBackground();
    void initWorld();
    void initLifeBar();
    void initPauseButton();
    void initPlayerFighter(int p_fighterID);

    inline CCPoint getPlayerFighterPos() const
    {
        return m_PlayerFighterSprite->getPosition();
    }
    
    void pauseCallback();
    void actionCallbackND(CCNode *pSender, void *data);
    CCSprite* enemyExplosionAnimation(const char *name, int count, float delay, CCPoint pos);
    CCSprite* playerBulletExplosionAnimation(const char *name, CCPoint pos);
    
    void clickBack();
    void clickContinue();
    
    virtual void ccTouchesBegan(CCSet* touches, CCEvent* event);
    virtual void ccTouchesMoved(CCSet* touches, CCEvent* event);
    virtual void ccTouchesEnded(CCSet* touches, CCEvent* event);
    
    void changeProfile(CCInteger* blood);
    
    void enemyExplosion(CCInteger* tag);
    
    void playerExplosion(CCObject* obj);
    
    void playerBulletExplosion(CCInteger* tag);
    
    void destroyBullet(CCDictionary* dict);
    
    void destroyEnemyFighter(EnemyFighterSprite* enemy);
    
    void destroyBonus(CCDictionary* dict);
    
    void payoff(CCInteger* type);
    
    //LAYER_CREATE_FUNC_PARAM(BattleActionLayer, CCDictionary*, p_params);
    LAYER_CREATE_FUNC(BattleActionLayer);
};


#endif
